﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;

namespace G
{
    public static class Common
    {

        /// <summary>
        /// 退出应用程序
        /// </summary>
        /// <param name="application"></param>
        public static void ExitApplication(this Application application)
        {
            throw new ExitExeption("退出程序！");
        }
    }

    public static class StreamExtention
    {
        public static byte[] GetBytes(this Stream stream)
        {
            byte[] buffer = new byte[stream.Length];
            stream.Seek(0, SeekOrigin.Begin);
            stream.Read(buffer, 0, buffer.Length);
            return buffer;
        }

        public static void Write(this Stream strem, byte[] buffer)
        {
            strem.Write(buffer, 0, buffer.Length);
        }

    }
    public static class StringExtention
    {
        public static byte[] GetBytes(this string str)
        {
            return System.Text.UTF8Encoding.UTF8.GetBytes(str);
        }
    }
    public static class DateTimeExtention
    {
        /// <summary>
        /// 获取时间戳
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static int GetTimestamp(this DateTime time)
        {
            TimeSpan ts = time - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return (int)ts.TotalSeconds;
        }



        public static readonly DateTime OriginalTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);


        static DateTimeExtention()
        {
            OriginalTime = new DateTime(0x7b2, 1, 1);
        }

        public static DateTime TimestampToDateTime(long timestamp)
        {
            return OriginalTime.AddSeconds(timestamp);
        }

    }
}
